package ru.spb.osll.myfit.server.parser;

import org.junit.Test;
import ru.spb.osll.myfit.common.Define;
import ru.spb.osll.myfit.common.PageElement;

import static org.junit.Assert.*;

/**
 * Created by IntelliJ IDEA.
 * User: Vassar
 * Date: 05.05.2011
 * Time: 12:46:04
 * To change this template use File | Settings | File Templates.
 */
public class DefineElementParserTest {
  private DefineElementParser defineParser = new DefineElementParser();

  @Test
  public void testValideBracesDefine(){
    String line = "!define MYTEST.someVar {This is [the] text (of my) variable}";

    assertTrue(defineParser.matches(line));

    PageElement element = defineParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Define);

    assertEquals("MYTEST.someVar", ((Define)element).getNameVariable());
    assertEquals("This is [the] text (of my) variable",
                ((Define)element).getValueVariable());
  }

  @Test
  public void testValideBracketsDefine(){
    String line = "!define   user.name   [This is {the} text (of my) variable 123]    ";

    assertTrue(defineParser.matches(line));

    PageElement element = defineParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Define);

    assertEquals("user.name", ((Define)element).getNameVariable());
    assertEquals("This is {the} text (of my) variable 123",
                ((Define)element).getValueVariable());
  }

  @Test
  public void testValideParenthesisDefine(){
    String line = "!define someVar123 (This is [the] text  12 345{of my} variable)";

    assertTrue(defineParser.matches(line));

    PageElement element = defineParser.parse(line);
    assertNotNull(element);
    assertTrue(element instanceof Define);

    assertEquals("someVar123", ((Define)element).getNameVariable());
    assertEquals("This is [the] text  12 345{of my} variable",
                ((Define)element).getValueVariable());
  }

  @Test
  public void testValide2BracesDefine(){
    String line = "!define MYTEST.someVar {This is { my} variable}";

    assertFalse(defineParser.matches(line));
  }

  @Test
  public void testValide2BracketsDefine(){
    String line = "!define MYTEST.someVar [This is [ my] variable]";

    assertFalse(defineParser.matches(line));
  }

  @Test
  public void testValide2ParenthesisDefine(){
    String line = "!define MYTEST.someVar (This is ( my) variable)";

    assertFalse(defineParser.matches(line));
  }
}
